AddCSLuaFile()

DEFINE_BASECLASS( "class_default" )

local PLAYER = {}

PLAYER.DisplayName			= "Bloodmage"

PLAYER.WalkSpeed = 170
PLAYER.MaxHealth			= 175
PLAYER.StartHealth			= 175

PLAYER.AttackSpeed = 1.75
PLAYER.WeaponDamageMin = 4
PLAYER.WeaponDamageMax = 7

PLAYER.MainhandModel = "models/devin/rpgdm_weapons/basic/broadsword.mdl"
PLAYER.OffhandModel = ""
PLAYER.MainHand = nil
PLAYER.OffHand = nil

PLAYER.ResourceAmount = 0
PLAYER.ResourceMax = 150
PLAYER.RegenTime = 2
PLAYER.RegenAmount = 5
PLAYER.ResourceColor = Color(125, 15, 15, 255)

PLAYER.Spells = {
	12102,
	48317,
	48311,
	48314,
	55313,
	13010,
	13011
}

PLAYER.Gear = {
	10,
	11,
	12
}

function PLAYER:SetupDataTables()

	BaseClass.SetupDataTables( self )

end

function PLAYER:SetupResources()
	print("SETTING UP RESOURCES")
	self.Player.Resource = self.ResourceAmount
	self.Player.ResourceMax = self.ResourceMax
	self.Player.NextResource = CurTime() + self.RegenTime
	self.Player.ResourceTimer = self.RegenTime
	self.Player.ResourceRegen = false
	self.Player.ResourceRegenAmount = self.RegenAmount
	self.Player.ResourceColor = self.ResourceColor
	net.Start("ReceivePlayerResources")
	net.WriteTable({self.Player.Resource, self.Player.ResourceMax, self.Player.ResourceColor, self.Player})
	net.Broadcast()
end

function PLAYER:Spawn()
	local col = team.GetColor(self.Player:Team())
	self.Player:SetPlayerColor( Vector(	col.r/255, col.g/255, col.b/255 ) )
	self.Player:SetWeaponColor( Vector( col.r/255, col.g/255, col.b/255 ) )
	timer.Destroy("SpeedModCharge")
	self.Player:SetWalkSpeed(self.WalkSpeed)
	self:Loadout()
	self:SetupGear()
	self:SetupSpells()
	self:SetupResources()
	net.Start("SendSelfMaxHealth")
	net.WriteFloat(self.MaxHealth)
	net.Send(self.Player)
end

function PLAYER:SetupGear()
	self.Player.tempEquippedItems = self.Gear
	SetEquipped(self.Player, self.Gear)
end

function PLAYER:SetupSpells()
	if(!self.Player.tempSpells)then
		SetSpells(self.Player, self.Spells)
		timer.Simple(0.1, function()
			net.Start("SendPlayerSpells")
			net.WriteTable(self.Spells)
			net.Send(self.Player)
		end)
	end
end

function PLAYER:Loadout()
	self.MainHand = ents.Create("prop_dynamic")
	self.MainHand:SetModel(self.MainhandModel)
	self.MainHand:PhysicsInit(SOLID_VPHYSICS)
	self.MainHand:SetMoveType(MOVETYPE_NONE)
	self.MainHand:SetSolid( SOLID_VPHYSICS )
	self.MainHand:SetParent(self.Player)
	self.MainHand:AddEffects( EF_BONEMERGE )
	self.Player:SetNWEntity("MainWep", self.MainHand)
	self.OffHand = ents.Create("prop_dynamic")
	self.OffHand:SetModel(self.OffhandModel)
	self.OffHand:PhysicsInit(SOLID_VPHYSICS)
	self.OffHand:SetMoveType(MOVETYPE_NONE)
	self.OffHand:SetSolid( SOLID_VPHYSICS )
	self.OffHand:SetParent(self.Player)
	self.OffHand:AddEffects( EF_BONEMERGE )
	self.Player:SetNWEntity("OffWep", self.OffHand)
	self.Player:Give( "weapon_all" )
	local weapon = self.Player:GetWeapon("weapon_all")
		
	weapon.AttackSpeed = self.AttackSpeed
	weapon.MinWeaponDamage = self.WeaponDamageMin
	weapon.MaxWeaponDamage = self.WeaponDamageMax
	weapon.WeaponType = "Ranged"
	weapon.WeaponReach = 1024
	weapon.WeaponStance = "bloodmage"
	self.Player:SetNWString("HoldType", "slam")
end

function PLAYER:OnHit()
	target = self.Player:GetNetworkedEntity("Target")
	UpdatePlayerResource(self.Player, 10)
end
	
player_manager.RegisterClass( "class_bloodmage", PLAYER, "class_default" )